package com.cskaoyan.day7._07_stream;

import java.util.List;
import java.util.stream.Collectors;

/**
 * distinct 去重中间操作
 * @author Common-zhou
 * @since 2023-03-06 15:21
 */
public class Demo5 {
    public static void main(String[] args) {
        List<Student> studentList = new StudentList().studentList;


        // 先筛选出所有北京的同学
        List<Student> collect = studentList.stream().filter(stu -> Student.Address.BJ.equals(stu.getAddress()))
            .collect(Collectors.toList());

        System.out.println(collect);
        // 11个
        System.out.println(collect.size());


        // 现在想去重 怎么去

        List<Student> distinctBeijingStudent = studentList.stream().filter(stu -> Student.Address.BJ.equals(stu.getAddress()))
            // 怎么去重的？ hashCode 和equals
            .distinct()
            .collect(Collectors.toList());

        // kk 和qq重复了
        // 底层就是一个LinkedHashSet
        System.out.println(distinctBeijingStudent.size());


    }
}
